import java.util.ArrayList;

import javax.swing.JFrame;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FileServer implements Runnable{

	private java.io.OutputStream out;
	private String data1;
	public FileServer(java.io.OutputStream o,String d){
		this.out = o;
		this.data1 = d;
	}
	public void run(){
		try{
			String data = data1.trim();// dir c:\\winnt
			if(data.substring(0,3).trim().equals("dir")){
				java.io.File file = new java.io.File(data.substring(4,data.length()));
				if(file.isDirectory()){
					String[] arrayList = file.list();
					out.write("p".getBytes());
					for(int i=0;i<arrayList.length;i++){
						out.write(arrayList[i].getBytes());
						out.write("\r\n".getBytes());
					}
					out.write("end".getBytes());
					out.write("\r\n".getBytes());
					out.flush();
				}
				else if(file.isFile()){
					java.io.FileInputStream fileIn = new java.io.FileInputStream(file);
					int i;
					out.write("f".getBytes());
					while((i=fileIn.read())!=-1){
						System.out.print(i);
						out.write(i);
					}
					out.flush();
				}
			}
			else if(data.substring(0,3).trim().equals("dia")){
				JFrame frame = new JFrame();
				NewJDialog inst = new NewJDialog(frame,data);
				inst.setVisible(true);
				out.flush();
			}

		}catch(Exception e){
			try{
				out.write("p".getBytes());
				out.write(" the direction is not exist".getBytes());
				out.write("\r\n".getBytes());
				out.write("end".getBytes());
				out.write("\r\n".getBytes());
				out.flush();
			}catch(Exception e1){}
		}finally{
			try{

			}catch(Exception e){

			}
		}
	}

}
